package reciprocal;

import java.util.Random;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Eagle
 */
public class myCommonTask {

        public static int[] connInfo(int connIndex, int qGrpN, int tGrpN, int dGrpN)

        {

            int infoArray[]=new int[3]; //[preCellId][postCellId][groupSize]
            if (connIndex<dGrpN*2){
                infoArray[0]=connIndex;
                switch (connIndex%2) {
                    case 1:
                        infoArray[1]=infoArray[0]--;
                        break;
                    case 0:
                        infoArray[1]=infoArray[0]++;
                        break;
                }
                infoArray[2]=2;
                return infoArray;
            }
            else if (connIndex<dGrpN*2+tGrpN*6){
                int preCellId=connIndex-dGrpN*2;
                int postkey=preCellId;
                preCellId=(int) Math.floor(preCellId/2);
                preCellId+=dGrpN*2;
                infoArray[0]= preCellId;
                switch (postkey%6) {
                    case 0:
                    case 3:
                        infoArray[1]=infoArray[0]++;
                        break;
                    case 2:
                    case 5:
                        infoArray[1]=infoArray[0]--;
                        break;
                    case 1:
                        infoArray[1]=infoArray[0]+2;
                        break;
                    case 4:
                        infoArray[1]=infoArray[0]-2;
                        break;
                }
                infoArray[2]= 3;
                return infoArray;
            }
            else {
                int preCellId=connIndex-dGrpN*2-tGrpN*6;
                int postkey=preCellId;
                preCellId=(int) Math.floor(preCellId/3);
                preCellId+=dGrpN*2+tGrpN*3;
                infoArray[0]=preCellId;
                switch (postkey%12) {
                    case 0:
                    case 4:
                    case 8:
                        infoArray[1]=infoArray[0]++;
                        break;
                    case 1:
                    case 5:
                        infoArray[1]=infoArray[0]+2;
                        break;
                    case 2:
                        infoArray[1]=infoArray[0]+3;
                        break;
                    case 3:
                    case 7:
                    case 11:
                        infoArray[1]=infoArray[0]--;
                        break;
                    case 6:
                    case 10:
                        infoArray[1]=infoArray[0]-2;
                        break;
                    case 9:
                        infoArray[1]=infoArray[0]-3;
                        break;
                }
                infoArray[2]=4;
                return infoArray;
        }
    }
    	public static void shuffleArray(int[] a) {
		int n = a.length;
		Random random = new Random();
		random.nextInt();
		for (int i = 0; i < n; i++) {
			int change = i + random.nextInt(n - i);
			swap(a, i, change);
		}
	}

        private static void swap(int[] a, int i, int change) {
		int helper = a[i];
		a[i] = a[change];
		a[change] = helper;
	}


        public static void shuffleArray(boolean[] a) {
		int n = a.length;
		Random random = new Random();
		random.nextInt();
		for (int i = 0; i < n; i++) {
			int change = i + random.nextInt(n - i);
			swap(a, i, change);
		}
	}

        private static void swap(boolean[] a, int i, int change) {
		boolean helper = a[i];
		a[i] = a[change];
		a[change] = helper;
	}

        public static void debugListArray(int[] array)
        {
            for (int i=0;i<array.length;i++)
            {
                System.out.println(i+":"+array[i]);
            }
        }

        public static void debugListArray(boolean[] array)
        {
            for (int i=0;i<array.length;i++)
            {
                System.out.println(i+":"+array[i]);
            }
        }


        void dp (int p)
        {
           System.out.println(p);
        }


        public static void debugListArrayCompact(int[] array)
        {
            for (int i=0;i<array.length;i++)
            {
                System.out.print(array[i]+",");
            }
            System.out.println();
        }


}

